#@admin_layout()
#define admin_main()
<div class="layui-btn-group demoTable">
	<button class="layui-btn" data-type="addBlog">写文章</button>
	<button class="layui-btn" data-type="import" id="import"><i class="layui-icon">&#xe67c;</i>上传导入</button>
	<a class="layui-btn" href="/blog/exportExcel" data-type="download"><i class="layui-icon">&#xe60a;</i>下载表格</a>
	<button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
	<button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
	<button class="layui-btn" data-type="isAll">验证是否全选</button>
</div>

<table class="layui-table" lay-data="{height: 'full-200', url:'/blog/list', page:true, id:'id',cellMinWidth: 80}" lay-filter="demo">
	<thead>
	<tr>
		<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
		<th lay-data="{field:'id', sort: true, fixed: true}">ID</th>
		<th lay-data="{field:'title'}">标题</th>
		<th lay-data="{field:'content', sort: true}">内容</th>
		<th lay-data="{field:'create_time', sort: true}">创建时间</th>
		<th lay-data="{field:'update_time', sort: true}">更新时间</th>
		<th lay-data="{field:'experience', sort: true}">积分</th>
        <th lay-data="{fixed: 'right', align:'center', toolbar: '#barDemo', minWidth :150}"></th>
	</tr>
	</thead>
</table>

<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

#end

#define admin_script()
<script>
	layui.use(['upload','table'], function(){
		var table = layui.table,
				upload = layui.upload;
		//监听表格复选框选择
		table.on('checkbox(demo)', function(obj){
			console.log(obj)
		});
		//监听工具条
		table.on('tool(demo)', function(obj){
			var data = obj.data;
			if(obj.event === 'detail'){
				layer.msg('ID：'+ data.id + ' 的查看操作');
			} else if(obj.event === 'del'){
				layer.confirm('真的删除行么', function(index){
					obj.del();
					layer.close(index);
				});
			} else if(obj.event === 'edit'){
				layer.alert('编辑行：<br>'+ JSON.stringify(data))
			}
		});

		var $ = layui.$, active = {
			download: function(){ // 下载表格
				location.href = "/blog/exportExcel"
			},
			addBlog: function(){
				location.href = "/blog/add";
			},
			getCheckData: function(){ //获取选中数据
				var checkStatus = table.checkStatus('idTest')
						,data = checkStatus.data;
				layer.alert(JSON.stringify(data));
			}
			,getCheckLength: function(){ //获取选中数目
				var checkStatus = table.checkStatus('idTest')
						,data = checkStatus.data;
				layer.msg('选中了：'+ data.length + ' 个');
			}
			,isAll: function(){ //验证是否全选
				var checkStatus = table.checkStatus('idTest');
				layer.msg(checkStatus.isAll ? '全选': '未全选')
			}
		};

		$('.demoTable .layui-btn').on('click', function(){
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		upload.render({
			elem: '#import'
			,url: '/blog/importExcel'
			,accept: 'file' //普通文件
			,exts: 'xls' //只允许上传压缩文件
			,done: function(res){
				console.log(res)
				if(res.error){
					layer.alert(res.error)
				} else{
					layer.alert("success:"+res.success+"lost:"+res.lost+"count:"+res.count);
				}
			}
		});
	});
</script>
#end